/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package czStvDpds.graphics3D.geometry;

import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;

//http://pic.dhe.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.opengl%2Fdoc%2Fopenglrf%2FglTexEnv.htm
//
//GL_TEXTURE_ENV - GL_TEXTURE_ENV_MODE - !!GL_MODULATE!!, GL_DECAL, GL_BLEND,
//                                       GL_REPLACE, GL_ADD or GL_COMBINE
//               - GL_COMBINE_RGB, GL_COMBINE_ALPHA (poud GL_COMBINE) - 
//                                       !!GL_MODULATE!!, GL_REPLACE, GL_ADD,
//                                       GL_ADD_SIGNED, GL_INTERPOLATE,
//                                       GL_DOT3_RGB, GL_DOT3_RGBA,GL_SUBTRACT
//               - GL_TEXTURE_ENV_COLOR - rgba barva !!(0,0,0,0)!!
//
//               - GL_SOURCE(0-2)_(RGB,ALPHA) - GL_TEXTURE, GL_CONSTANT, 
//                                       GL_PRIMARY_COLOR, GL_PREVIOUS, GL_TEXTURE(0-31)
//               - GL_OPERAND(0,1)_RGB - !!GL_SRC_COLOR!!, GL_ONE_MINUS_SRC_COLOR,
//                                       GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
//               - GL_OPERAND(0,1)_ALPHA - !!GL_SRC_ALPHA!!, GL_ONE_MINUS_SRC_ALPHA
//                  (GL_OPERAND2_(ALPHA,RGB) musí být GL_SRC_ALPHA)
/**
 * Objekt reprezentující nastavení pro modulaci textur
 *
 * @author divad
 */
public class TextureEnvironment {

    public static final int ENVMODE_MODULATE = GL11.GL_MODULATE, ENVMODE_DECAL = GL11.GL_DECAL, ENVMODE_BLEND = GL11.GL_BLEND, ENVMODE_REPLACE = GL11.GL_REPLACE, ENVMODE_ADD = GL11.GL_ADD, ENVMODE_COMBINE = GL13.GL_COMBINE;
    private int environmentMode = TextureEnvironment.ENVMODE_MODULATE;
    public static final int CMODE_REPLACE = GL11.GL_REPLACE, CMODE_MODULATE = GL11.GL_MODULATE, CMODE_ADD = GL11.GL_ADD, CMODE_ADD_SIGNED = GL13.GL_ADD_SIGNED, CMODE_SUBTRACT = GL13.GL_SUBTRACT, CMODE_INTERPOLATE = GL13.GL_INTERPOLATE, CMODE_DOT3_RGB = GL13.GL_DOT3_RGB, CMODE_DOT3_RGBA = GL13.GL_DOT3_RGBA;
    private int combineModeRGB = TextureEnvironment.CMODE_MODULATE;
    private int combineModeALPHA = TextureEnvironment.CMODE_MODULATE;
    public static final int SOURCE_TEXTURE = GL11.GL_TEXTURE, SOURCE_CONSTANT = GL13.GL_CONSTANT, SOURCE_PRIMARY_COLOR = GL13.GL_PRIMARY_COLOR, SOURCE_PREVIOUS = GL13.GL_PREVIOUS, SOURCE_TEXTURE0 = GL13.GL_TEXTURE0;
    private int source0RGB = TextureEnvironment.SOURCE_TEXTURE;
    private int source1RGB = TextureEnvironment.SOURCE_PREVIOUS;
    private int source2RGB = TextureEnvironment.SOURCE_CONSTANT;
    private int source0ALPHA = TextureEnvironment.SOURCE_TEXTURE;
    private int source1ALPHA = TextureEnvironment.SOURCE_PREVIOUS;
    private int source2ALPHA = TextureEnvironment.SOURCE_CONSTANT;
    public static final int OPERAND_SRC_COLOR = GL11.GL_SRC_COLOR, OPERAND_ONE_MINUS_SRC_COLOR = GL11.GL_ONE_MINUS_SRC_COLOR, OPERAND_SRC_ALPHA = GL11.GL_SRC_ALPHA, OPERAND_ONE_MINUS_SRC_ALPHA = GL11.GL_ONE_MINUS_SRC_ALPHA;
    private int operand0RGB = TextureEnvironment.OPERAND_SRC_COLOR;
    private int operand1RGB = TextureEnvironment.OPERAND_SRC_COLOR;
    private int operand0ALPHA = TextureEnvironment.OPERAND_SRC_ALPHA;
    private int operand1ALPHA = TextureEnvironment.OPERAND_SRC_ALPHA;
    private FloatBuffer environmentColor;

    public TextureEnvironment() {
        environmentColor = BufferUtils.createFloatBuffer(4);
    }

    public TextureEnvironment(TextureEnvironment environment) {
        if (environment != null) {
            this.setCombineModeALPHA(environment.getCombineModeALPHA());
            this.setCombineModeRGB(environment.getCombineModeRGB());
            this.setEnvironmentColor(environment.getEnvironmentColor());
            this.setEnvironmentMode(environment.getEnvironmentMode());
            this.setOperand0ALPHA(environment.getOperand0ALPHA());
            this.setOperand1ALPHA(environment.getOperand1ALPHA());
            this.setOperand0RGB(environment.getOperand0RGB());
            this.setOperand1RGB(environment.getOperand1RGB());
            this.setSource0ALPHA(environment.getSource0ALPHA());
            this.setSource0RGB(environment.getSource0RGB());
            this.setSource1ALPHA(environment.getSource1ALPHA());
            this.setSource1RGB(environment.getSource1RGB());
            this.setSource2ALPHA(environment.getSource2ALPHA());
            this.setSource2RGB(environment.getSource2RGB());
        } else {
            environmentColor = BufferUtils.createFloatBuffer(4);
        }
    }

    public int getCombineModeALPHA() {
        return combineModeALPHA;
    }

    public int getCombineModeRGB() {
        return combineModeRGB;
    }

    public FloatBuffer getEnvironmentColor() {
        return environmentColor;
    }

    public int getEnvironmentMode() {
        return environmentMode;
    }

    public int getOperand0ALPHA() {
        return operand0ALPHA;
    }

    public int getOperand0RGB() {
        return operand0RGB;
    }

    public int getOperand1ALPHA() {
        return operand1ALPHA;
    }

    public int getOperand1RGB() {
        return operand1RGB;
    }

    public int getSource0ALPHA() {
        return source0ALPHA;
    }

    public int getSource0RGB() {
        return source0RGB;
    }

    public int getSource1ALPHA() {
        return source1ALPHA;
    }

    public int getSource1RGB() {
        return source1RGB;
    }

    public int getSource2ALPHA() {
        return source2ALPHA;
    }

    public int getSource2RGB() {
        return source2RGB;
    }
    ////////////settery/////////////////////

    /**
     * CMODE_REPLACE, CMODE_MODULATE, CMODE_ADD, CMODE_ADD_SIGNED,
     * CMODE_SUBTRACT, CMODE_INTERPOLATE, CMODE_DOT3_RGB, CMODE_DOT3_RGBA
     *
     * @param combineModeALPHA
     */
    public void setCombineModeALPHA(int combineModeALPHA) {
        this.combineModeALPHA = combineModeALPHA;
    }

    /**
     * CMODE_REPLACE, CMODE_MODULATE, CMODE_ADD, CMODE_ADD_SIGNED,
     * CMODE_SUBTRACT, CMODE_INTERPOLATE, CMODE_DOT3_RGB, CMODE_DOT3_RGBA
     *
     * @param combineModeRGB
     */
    public void setCombineModeRGB(int combineModeRGB) {
        this.combineModeRGB = combineModeRGB;
    }

    /**
     * r,g,b,a
     *
     * @param environmentColor
     */
    public void setEnvironmentColor(FloatBuffer environmentColor) {
        this.environmentColor = environmentColor;
    }

    /**
     * ENVMODE_MODULATE, ENVMODE_DECAL ENVMODE_BLEND, ENVMODE_REPLACE,
     * ENVMODE_ADD, ENVMODE_COMBINE
     *
     * @param environmentMode
     */
    public void setEnvironmentMode(int environmentMode) {
        this.environmentMode = environmentMode;
    }

    /**
     *
     * OPERAND_SRC_ALPHA, OPERAND_ONE_MINUS_SRC_ALPHA
     *
     * @param operand0ALPHA
     */
    public void setOperand0ALPHA(int operand0ALPHA) {
        this.operand0ALPHA = operand0ALPHA;
    }

    /**
     * OPERAND_SRC_COLOR, OPERAND_ONE_MINUS_SRC_COLOR, OPERAND_SRC_ALPHA,
     * OPERAND_ONE_MINUS_SRC_ALPHA
     *
     * @param operand0RGB
     */
    public void setOperand0RGB(int operand0RGB) {
        this.operand0RGB = operand0RGB;
    }

    /**
     * OPERAND_SRC_ALPHA, OPERAND_ONE_MINUS_SRC_ALPHA
     *
     * @param operand1ALPHA
     */
    public void setOperand1ALPHA(int operand1ALPHA) {
        this.operand1ALPHA = operand1ALPHA;
    }

    /**
     * OPERAND_SRC_COLOR, OPERAND_ONE_MINUS_SRC_COLOR, OPERAND_SRC_ALPHA,
     * OPERAND_ONE_MINUS_SRC_ALPHA
     *
     * @param operand1RGB
     */
    public void setOperand1RGB(int operand1RGB) {
        this.operand1RGB = operand1RGB;
    }

    /**
     * SOURCE_TEXTURE, SOURCE_CONSTANT, SOURCE_PRIMARY_COLOR, SOURCE_PREVIOUS,
     * SOURCE_TEXTURE0+n n=<0,31>
     *
     * @param source0ALPHA
     */
    public void setSource0ALPHA(int source0ALPHA) {
        this.source0ALPHA = source0ALPHA;
    }

    /**
     * SOURCE_TEXTURE, SOURCE_CONSTANT, SOURCE_PRIMARY_COLOR, SOURCE_PREVIOUS,
     * SOURCE_TEXTURE0+n n=<0,31>
     *
     * @param source0ALPHA
     */
    public void setSource0RGB(int source0RGB) {
        this.source0RGB = source0RGB;
    }

    /**
     * SOURCE_TEXTURE, SOURCE_CONSTANT, SOURCE_PRIMARY_COLOR, SOURCE_PREVIOUS,
     * SOURCE_TEXTURE0+n n=<0,31>
     *
     * @param source0ALPHA
     */
    public void setSource1ALPHA(int source1ALPHA) {
        this.source1ALPHA = source1ALPHA;
    }

    /**
     * SOURCE_TEXTURE, SOURCE_CONSTANT, SOURCE_PRIMARY_COLOR, SOURCE_PREVIOUS,
     * SOURCE_TEXTURE0+n n=<0,31>
     *
     * @param source0ALPHA
     */
    public void setSource1RGB(int source1RGB) {
        this.source1RGB = source1RGB;
    }

    /**
     * SOURCE_TEXTURE, SOURCE_CONSTANT, SOURCE_PRIMARY_COLOR, SOURCE_PREVIOUS,
     * SOURCE_TEXTURE0+n n=<0,31>
     *
     * @param source0ALPHA
     */
    public void setSource2ALPHA(int source2ALPHA) {
        this.source2ALPHA = source2ALPHA;
    }

    /**
     * SOURCE_TEXTURE, SOURCE_CONSTANT, SOURCE_PRIMARY_COLOR, SOURCE_PREVIOUS,
     * SOURCE_TEXTURE0+n n=<0,31>
     *
     * @param source0ALPHA
     */
    public void setSource2RGB(int source2RGB) {
        this.source2RGB = source2RGB;
    }
}
